﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using WPFExcelReport.Helpers;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class UIGSMATK : ViewBase
    {
        public VGSMATK TMV
        {
            get
            {
                return (VGSMATK)MV;
            }
        }

        #region ==CART===========
        public static readonly DependencyProperty CARTProperty = DependencyProperty.Register("CART",
            typeof(string), typeof(UIGSMATK),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCARTChanged));
        public string CART
        {
            get
            {
                return (string)GetValue(CARTProperty);
            }
            set
            {
                SetValue(CARTProperty, value);
                OnCARTChg(value);
            }
        }
        private static void OnCARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIGSMATK;
            if (src != null)
            {
                src.CART = (string)e.NewValue;

            }
        }
        public virtual void OnCARTChg(string value)
        { }
        #endregion

        #region ==IsRefresh===========
        public static readonly DependencyProperty IsRefreshProperty = DependencyProperty.Register("IsRefresh",
            typeof(bool), typeof(UIGSMATK),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsRefreshChanged));
        public bool IsRefresh
        {
            get
            {
                return (bool)GetValue(IsRefreshProperty);
            }
            set
            {
                SetValue(IsRefreshProperty, value);
             
            }
        }
        private static void OnIsRefreshChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIGSMATK;
            if (src != null)
            {
                src.IsRefresh = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsManual===========
        public static readonly DependencyProperty IsManualProperty = DependencyProperty.Register("IsManual",
            typeof(bool), typeof(UIGSMATK),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsManualChanged));
        public bool IsManual
        {
            get
            {
                return (bool)GetValue(IsManualProperty);
            }
            set
            {
                SetValue(IsManualProperty, value);

            }
        }
        private static void OnIsManualChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIGSMATK;
            if (src != null)
            {
                src.IsManual = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsGSSave===========
        public static readonly DependencyProperty IsGSSaveProperty = DependencyProperty.Register("IsGSSave",
            typeof(bool), typeof(UIGSMATK),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsGSSaveChanged));
        public bool IsGSSave
        {
            get
            {
                return (bool)GetValue(IsGSSaveProperty);
            }
            set
            {
                SetValue(IsGSSaveProperty, value);

            }
        }
        private static void OnIsGSSaveChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIGSMATK;
            if (src != null)
            {
                src.IsGSSave = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsCcopy===========
        public static readonly DependencyProperty IsCcopyProperty = DependencyProperty.Register("IsCcopy",
            typeof(bool), typeof(UIGSMATK),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCcopyChanged));
        public bool IsCcopy
        {
            get
            {
                return (bool)GetValue(IsCcopyProperty);
            }
            set
            {
                SetValue(IsCcopyProperty, value);

            }
        }
        private static void OnIsCcopyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIGSMATK;
            if (src != null)
            {
                src.IsCcopy = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==dwSD13===========
        public static readonly DependencyProperty dwSD13Property = DependencyProperty.Register("dwSD13",
            typeof(DataRow), typeof(UIGSMATK),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwSD13Changed));
        public DataRow dwSD13
        {
            get
            {
                return (DataRow)GetValue(dwSD13Property);
            }
            set
            {
                SetValue(dwSD13Property, value);
                OnSD13Chg(value); 
            }
        }
        private static void OndwSD13Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIGSMATK;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwSD13 = row;
            }
        }
        public virtual void OnSD13Chg(DataRow sd)
        { 
        }
        #endregion

        #region ==dwVAK===========
        public static readonly DependencyProperty dwVAKProperty = DependencyProperty.Register("dwVAK",
            typeof(DataRow), typeof(UIGSMATK),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwVAKChanged));
        public DataRow dwVAK
        {
            get
            {
                return (DataRow)GetValue(dwVAKProperty);
            }
            set
            {
                SetValue(dwVAKProperty, value);
                OnVAKChg(value);
            }
        }
        private static void OndwVAKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIGSMATK;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwVAK = row;
            }
        }
        public virtual void OnVAKChg(DataRow sd)
        {
        }
        #endregion 

        public UIGSMATK()
        {
            
        }

        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
        }
        
        public void GetInfo()
        {
            INFO = "";
            if (TBMain.Rows.Count == 0)
                return;
            string c = "";
            string yc = "";
            foreach (DataRow row in TBMain.Rows)
            {
                string sv = row["GSMRANT"].ToString();
                if (sv == "")
                    sv = "0";
                if (sv == "0") break;

                INFO += Convert.ToDouble(sv) * 0.1 + row["GSMRSPZ"].ToString() + ";";
            }
        }
     
    }
}
